var rootview = ui("$");
var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var common = require("common");
var openHelper = require("helper/open");
var shareHelper = require("helper/share");
var http = require("helper/http");
var mallUrl = require("url/mall");
var qqmath = require("util/qqmath");
var lablePrice = ui("lablePrice")

var do_GridView_1 = ui("do_GridView_1");


rootview.setMapping({
    "productName.text" : "name",
    "lablePrice.tag" : "price",
    "lableStock.text" : "stock",
    "do_GridView_1.tag" : "bigImgItems",//新版图片集合
    "do_GridView_1.items" : "imgItems",//新版图片集合
    "do_GridView_1.visible" : "hasImg",
    "do_ALayout_title.tag" : "id", //商品id
    "lablePvCount.text": "pv",
    "lableGzCount.text": "concernCount"
});

rootview.on("dataRefreshed", function(){
	lablePrice.text = qqmath.getDight(lablePrice.tag, 2)+''; //加空格iphone后面多位小数
});

//图片浏览注册事件
do_GridView_1.on("touch", function(data){
	openHelper.open("source://view/reuse/imgBrowser.ui", {
		imgDatas :do_GridView_1.tag,index:data
	});
});

//分享
ui("btnShare").on("touch","",300, function(data, e) {
	page.fire("onShare",{
			showView: "true",
			shareTitle: ui("productName").text,
			shareContent: ui("productName").text,
			shareId: ui("do_ALayout_title").tag,//商品id
			shareType: shareHelper.type.MALL_PRODUCT,
			shareImage: ""
			});
})

//下架
ui("btnOffSell").on("touch", function(data, e) {
	//nf.toast("下架");
	var productId = ui("do_ALayout_title").tag;
	if(productId){
		http.post(mallUrl.url.product.offShelf, {id: productId}, function(data) {
			nf.toast("已下架");
			page.fire("mall_off_shelf_product");
		});
	}
})

//编辑
ui("btnEdit").on("touch", function(data, e) {
	//nf.toast("编辑");
	var productId = ui("do_ALayout_title").tag;
	if(productId){
		openHelper.open("source://view/qshop/manage/product/editProduct.ui",{productId:productId});
	}
})

ui("do_ALayout_title").on("touch", function(data, e) {
	var productId = ui("do_ALayout_title").tag;
	if(productId){
		openHelper.open("source://view/mall/product/main.ui",{id:productId});
	}
	
})